using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Champ
{
    //Parent class of Human and AI
    //This class standardizes the code interface for humans and computers so 
    //that we don't have to worry about which we are dealing with
    public class Player:Character
    {
        public PlayerIndex whichController;
        //Keeps track of exactly where the player sprite exists on the screen
        public enum playerState
        {
            playersTurn, neutralFirst, neutralSecond, neutralThird, againstFirst,
            againstSecond, againstThird, helpsFirst, helpsSecond, helpsThird, creationOne, creationTwo,
            creationThree, creationFour
        };

        int currentItem = 0;
        public int imageNum = 0;
        public playerState currentPlayerState;
        public GamePadState previousControllerState;
        //keeps track of anything that needs to know whether the player has made their decision
        public bool done = false;

        //-1 for monster, 0 for neutral (Lousy neutrals), 1 for player
        public int side = 0;

        public Item[] inventory = new Item[6];
        public Item[] lvlInventory = new Item[10];


        //Overridable function that allows players to choose sides
        public virtual void ChooseSide()
        {
              
        }

        //To display the character
        public override void characterDisplayData(Rectangle relativeScreenSize, Rectangle normalScreenSize)
        {   
            if (currentPlayerState == playerState.creationOne)
            {
                this.renderingRect.X = relativeScreenSize.X + 100;
                this.renderingRect.Y = relativeScreenSize.Y + 100;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 100;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 400;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.creationTwo)
            {
                this.renderingRect.X = relativeScreenSize.X + 250;
                this.renderingRect.Y = relativeScreenSize.Y + 100;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 100;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 400;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.creationThree)
            {
                this.renderingRect.X = relativeScreenSize.X + 425;
                this.renderingRect.Y = relativeScreenSize.Y + 100;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 100;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 400;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.creationFour)
            {
                this.renderingRect.X = relativeScreenSize.X + 575;
                this.renderingRect.Y = relativeScreenSize.Y + 100; 
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 100;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 400;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.playersTurn)
            {
                this.renderingRect.X = relativeScreenSize.X + 200;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.helpsFirst)
            {
                this.renderingRect.X = relativeScreenSize.X + 150;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.helpsSecond)
            {
                this.renderingRect.X = relativeScreenSize.X + 100;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.helpsThird)
            {
                this.renderingRect.X = relativeScreenSize.X + 50;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.neutralFirst)
            {
                this.renderingRect.X = relativeScreenSize.X + 150;
                this.renderingRect.Y = relativeScreenSize.Y + 230;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 60;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 190;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.neutralSecond)
            {
                this.renderingRect.X = relativeScreenSize.X + 100;
                this.renderingRect.Y = relativeScreenSize.Y + 230;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 60;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 190;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.neutralThird)
            {
                this.renderingRect.X = relativeScreenSize.X + 50;
                this.renderingRect.Y = relativeScreenSize.Y + 230;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 60;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 190;
                this.effects = SpriteEffects.None;
            }
            else if (currentPlayerState == playerState.againstFirst)
            {
                this.renderingRect.X = relativeScreenSize.X + 300;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.FlipHorizontally;
            }
            else if (currentPlayerState == playerState.againstSecond)
            {
                this.renderingRect.X = relativeScreenSize.X + 350;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.FlipHorizontally;
            }
            else if (currentPlayerState == playerState.againstThird)
            {
                this.renderingRect.X = relativeScreenSize.X + 400;
                this.renderingRect.Y = relativeScreenSize.Y + 250;
                this.renderingRect.Width = (normalScreenSize.Width / relativeScreenSize.Width) * 63;
                this.renderingRect.Height = (normalScreenSize.Height / relativeScreenSize.Height) * 200;
                this.effects = SpriteEffects.FlipHorizontally;
            }
        }

        //To deal with inventory
        public virtual void HandleInventory()
        {

        }

        //To deal with Loot
        public virtual void Looting()
        {

        }

        //Checks the button to see if it has been pushed and released
        public virtual bool CheckInputButtons(GameController.controllerButtons button)
        {
            return false;
        }
       
        //Get player name from gamertag
        public virtual void NamePlayer()
        {
            if (gamer != null)
            {
                playerName = gamer.Gamertag;
            }
            else
            {
                Guide.ShowSignIn(1, false);
            }
        }
       
    }
}